package com.ktg.mes.wm.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.wm.mapper.WmAssembleRecptLineMapper;
import com.ktg.mes.wm.domain.WmAssembleRecptLine;
import com.ktg.mes.wm.service.IWmAssembleRecptLineService;



/**
 * 物料组装入库Service业务层处理
 *
 * @author byteco
 * @date 2023-01-04
 */
@Service
public class WmAssembleRecptLineServiceImpl extends ServiceImpl<WmAssembleRecptLineMapper, WmAssembleRecptLine> implements IWmAssembleRecptLineService
{




    /**
     * 查询物料组装入库
     *
     * @param entity 物料组装入库
     * @param page 分页对象
     * @return 物料组装入库
     */
    @Override
    public IPage<WmAssembleRecptLine> queryPageList(WmAssembleRecptLine entity, Page<WmAssembleRecptLine> page) {
        QueryWrapper<WmAssembleRecptLine> lqw = new QueryWrapper<WmAssembleRecptLine>(entity);
        lqw.orderByDesc("create_time");
        IPage<WmAssembleRecptLine> pageList = this.page(page, lqw);
        return pageList;
    }

    /**
     * 查询物料组装入库
     *
     * @param entity 物料组装入库
     * @return 物料组装入库
     */
    @Override
    public List<WmAssembleRecptLine> queryList(WmAssembleRecptLine entity) {
        QueryWrapper<WmAssembleRecptLine> lqw = new QueryWrapper<WmAssembleRecptLine>(entity);
        lqw.orderByDesc("create_time");
        return this.list(lqw);
    }

    public WmAssembleRecptLine getInfo(Long id)
    {
        return this.getById(id);
    }


    /**
     * 新增物料组装入库
     *
     * @param entity 物料组装入库
     * @return 结果
     */
    @Override
    public void insert(WmAssembleRecptLine entity)
    {
        entity.setCreateBy(SecurityUtils.getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        this.save(entity);
    }

    /**
     * 修改物料组装入库
     *
     * @param entity 物料组装入库
     * @return 结果
     */
    @Override
    public boolean update(WmAssembleRecptLine entity)
    {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return this.updateById(entity);
    }

    /**
     * 批量删除物料组装入库
     *
     * @param recordIds 需要删除的物料组装入库主键
     * @return 结果
     */
    @Override
    public boolean delete(Long[] recordIds)
    {

        return this.removeByIds(Arrays.asList(recordIds));
    }

    /**
     * 删除物料组装入库信息
     *
     * @param recordId 物料组装入库主键
     * @return 结果
     */
    @Override
    public boolean delete(Long recordId)
    {
        return this.removeById(recordId);
    }

    private LambdaQueryWrapper<WmAssembleRecptLine> buildQueryWrapper(WmAssembleRecptLine entity) {
        LambdaQueryWrapper<WmAssembleRecptLine> lqw = Wrappers.lambdaQuery();
                    lqw.eq(entity.getItemRecptLineId() != null, WmAssembleRecptLine::getItemRecptLineId, entity.getItemRecptLineId());
                    lqw.eq(entity.getFromItemRecptLineId() != null, WmAssembleRecptLine::getFromItemRecptLineId, entity.getFromItemRecptLineId());
                    lqw.eq(entity.getQuantityRecived() != null, WmAssembleRecptLine::getQuantityRecived, entity.getQuantityRecived());
        return lqw;
    }
}
